import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../../components/base_refresh/base_refresh_simple_widget.dart';
import '../../../../components/no_more/no_data_sliver_list.dart';
import '../../../../utils/extension.dart';
import '../../common/ai_face_stencil_block.dart';
import '../../common/popup/ai_face_image_make_bottom_sheet.dart';
import '../../controllers/tabs/ai_tab_face_image_page_controller.dart';

class AiTabFaceImagePage extends GetView<AiTabFaceImagePageController> {
  const AiTabFaceImagePage({super.key});

  Widget _buildBody() {
    return CustomScrollView(
      slivers: [
        Text(
          '选择内容',
          style: TextStyle(fontSize: 14.w),
        ).sliver,
        10.verticalSpaceFromWidth.sliver,
        Obx(
          () {
            final data = controller.data;
            final blocks =
                data.slices(AiFaceStencilBlock.showModelCountMax).toList();
            return NoDataSliverList.separated(
              itemBuilder: (ctx, index) => AiFaceStencilBlock(
                blocks[index],
                onTap: (i) {
                  AiFaceImageMakeBottomSheet(
                    stencil: blocks[index][i],
                    onTapMake: (file) =>
                        controller.onTapMake(data[index], file),
                  ).show();
                },
              ),
              itemCount: blocks.length,
              noData: controller.dataInited,
              separatorBuilder: (ctx, i) => 10.verticalSpaceFromWidth,
            );
          },
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) =>
      BaseRefreshSimpleWidget(controller, child: _buildBody()).marginTop(19.w);
}
